//bigbigli 公众号：大李日志 B站号：bigbigli_大大李

#define BLINKER_WIFI 
#include <Blinker.h> 
 
 
char auth[] = "";//这里填写点灯秘钥
char ssid[] = "";//你的无线网名称
char pswd[] = "";//你的无线网密码
 
int freq = 50;     
int channel = 8;   
int resolution = 8; 
const int led = 15;
 
 
BlinkerButton Button1("btn-max"); 
BlinkerButton Button2("btn-min"); 
int servo_max=180,servo_min=0;
 
int calculatePWM(int degree)
{ 
  const float deadZone = 6.4;
  const float max = 32;
  if (degree < 0)
    degree = 0;
  if (degree > 180)
    degree = 180;
  return (int)(((max - deadZone) / 180) * degree + deadZone);
}
 
void button1_callback(const String & state)    
{    
  BLINKER_LOG("get button state: ", servo_max); 
  ledcWrite(channel, calculatePWM(180));  
  Blinker.vibrate();  
} 
void button2_callback(const String & state)   
{         
  BLINKER_LOG("get button state: ", servo_min);  
  ledcWrite(channel, calculatePWM(90));
  Blinker.vibrate();
}
 
void setup()    
{   
  Serial.begin(115200);   
  ledcSetup(channel, freq, resolution); // 设置通道
  ledcAttachPin(led, channel);          // 将通道与对应的引脚连接
  BLINKER_DEBUG.stream(Serial);    
  Blinker.begin(auth, ssid, pswd); 
  Button1.attach(button1_callback);   
  Button2.attach(button2_callback);     
}
 
void loop() 
{   
Blinker.run();   
}
